package com.neuedu.my12306.web;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.my12306.entity.TicketInfo;
import com.neuedu.my12306.service.ITicketInforService;
import com.neuedu.my12306.service.impl.ITicketInfoServiceImpl;
import com.neuedu.my12306.util.DateUtil;

/**
 * Servlet implementation class TicketAddServlet
 */
@WebServlet("/TicketAddServlet.do")
public class TicketAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private ITicketInforService ticketInforService = null;

    public TicketAddServlet() {
        super();
        ticketInforService = new ITicketInfoServiceImpl();
      
    }


	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		boolean ret = false;
		int id = 0;
		String startStation =  request.getParameter("startStation");
		String endStation = request.getParameter("endStation");
		String startDate1 = request.getParameter("startDate");
		String startTime1 =  request.getParameter("startTime");
		Date startTime  = DateUtil.pareTime(startTime1);
		String userName = request.getParameter("userName");
		Date startDate = DateUtil.pareDate(startDate1);
		
		TicketInfo ticketInfo = new TicketInfo(id, startStation, endStation, startDate, startTime, userName);
		ret = ticketInforService.reg(ticketInfo);
		if (ret) {
			request.getSession().setAttribute("MSG", "新增成功");
		}else {
			request.getSession().setAttribute("MSG", "新增失败");
		}
		
		request.getSession().setAttribute("BACKURL", request.getContextPath() + "/TickeAdminServlet.do");
		response.sendRedirect(request.getContextPath() + "/error.jsp");
	}
		
}


